package com.lufei.lu_retrofit;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lufei.lu_retrofit.vlayout.AesUtil;
import com.lufei.lu_retrofit.vlayout.LinearLayoutHelperActivity;
import com.lufei.lu_retrofit.vlayout.MessageEvent;
import com.zyao89.view.zloading.ZLoadingDialog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @InjectView(R.id.btn_start)
    Button btnStart;
    @InjectView(R.id.btn_stop)
    Button btnStop;
    @InjectView(R.id.id_event_text)
    TextView idEventText;
    private ZLoadingDialog zLoadingDialog;
    private int xc = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        EventBus.getDefault().register(this);
        zLoadingDialog = new ZLoadingDialog(MainActivity.this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        EventBus.getDefault().unregister(this);
    }

    @OnClick({R.id.btn_start, R.id.btn_stop})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_start:
                startActivity(new Intent(this, LinearLayoutHelperActivity.class));
                break;
            case R.id.btn_stop:
//                EventBus.getDefault().post(new MessageEvent("name1","password1"));
//                EventBus.getDefault().postSticky(new MessageEvent("name1", "password1"));   asfdais
                //   jdagjhc.jpg
                //
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void messageEventBus(MessageEvent event) {
//        data.add(event.name + "___" + event.password);
        String name = event.name;
        String key="12345678901234567";
        String decode = AesUtil.decode(key, name);
        idEventText.setText(decode + "___" +name);
    }
}
